package leetcode.D100.T28;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-11 1:22:31 星期五
 */

class Solution {
    public int strStr(String haystack, String needle) {
        if (needle.equals(""))
            return 0;
        int pos = -1;
        for(int i=0; i<haystack.length(); ++i) {
            if (i + needle.length() > haystack.length())
                break;
            boolean flag = true;
            for(int j=0; j<needle.length(); ++j) {
                if (haystack.charAt(i+j) != needle.charAt(j)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                pos = i;
                break;
            }
        }
        return pos;
    }
}